<template>
	<view class="offerNoticeWrapper">
		<view class="title">
			{{isedit?'编辑录用通知':'查看录用通知'}}
		</view>
		<!-- <textarea class="textarea" ref="textarea" :value="text" @input="onInput" placeholder="请输入您的常用回复" hold-keyboard confirm-type="send"  :maxlength="-1" /> -->
		<view v-if="isedit" class="textareaBox">
		  <u--textarea
		    v-model="text"
			class="textarea"
		    placeholder="请输入内容"
		    border="surround"
		    maxlength="5000"
		    count
			height='500'
		  ></u--textarea>
		</view>
		<view class="textareaBox textareaBoxView" v-else>
			{{text}}
		</view>
		<view class="addBox" v-if="isedit">
			<view class="addcyy" @tap="submit" >
				保存
			</view>			
		</view>
	</view>
</template>

<script>
	import api from '@/common/api.js'
	import {
		req
	} from '@/common/vmeitime-http/'
	import covertContactMessage from "@/wfc/messages/covertContactMessage";
	import QuoteInfo from "@/wfc/model/quoteInfo";
	import store from "@/store";	
	import wfc from "@/wfc/client/wfc";
	import Draft from "../util/draft";
	import { getInteractionDic, setImInteraction } from "@/common/im";
	export default {
		data() {
			return {
				text:'',
				isedit:true,
				id:'',
				jobId:'',
				dfid:'',
				companyName:'',
				jobName:''
			}
		},
		onLoad(e) {
			if(e.type){
				this.isedit=false
				this.text = JSON.parse(e.content).companyName
			}else{
				this.jobId = e.jobId
				this.dfid = e.dfid
			}
			this.getinfo()
		},
		methods: {
			onInput(event){
				this.text = event.detail.value;
			},
			getinfo(id){
				req('POST', api.jobContact2, {
						jobId:this.jobId,
						hunterId:this.dfid,
					}).then(res=>{
						console.log('让我看看面试的信息是啥',res);
						this.companyName = res.result.companyName
						this.jobName = res.result.job.jobName
					})
			},
			submit(){
				if(!this.companyName){
					uni.showToast({
						title: '未查询到公司信息',
						icon:'error'
					})
					return
				}
				const obj = {
					companyName:this.companyName,
					jobName:this.jobName,
					offerNotice:this.text
				};
				const field = getInteractionDic("notice2");
				let phoneMessageContent;
				phoneMessageContent = new covertContactMessage("notice2", JSON.stringify(obj));
				console.log('-----------',field, 1,this.jobId,this.dfid);
				setImInteraction(field, 1,this.jobId,this.dfid);
				// let phoneMessageContent = new TextMessageContent('15631143241');
				let quotedMessage = store.state.conversation.quotedMessage;
				if (quotedMessage) {
					let quoteInfo = QuoteInfo.initWithMessage(quotedMessage);
					phoneMessageContent.setQuoteInfo(quoteInfo);
					store.quoteMessage(null);
				}
				let currentConversation = store.state.conversation.currentConversationInfo.conversation;
				wfc.sendConversationMessage(currentConversation, phoneMessageContent);
				Draft.setConversationDraft(currentConversation, "", null);
				uni.navigateTo({
					name:'ConversationPage'
				})
				// this.$router.push({
				// 	name: "ConversationPage",
				// 	params: {},
				// });
			},
		}
	}
</script>

<style lang="scss" scoped> 
.offerNoticeWrapper{
	width: 100%;
	height: 100%;
	position: relative;
	.title{
		width: 85.5%;
		margin: 10px auto;
		text-align: left;
		font-size: 20px;
		font-weight: bold;
	}
	.textareaBox{
		width: 95%;
		height: fit-content;
		background-color: #f2f2f2;
		margin: 10px auto;
		padding: 10px;
		box-sizing: border-box;
	}
	.textareaBoxView{
		height: 500px;
	}
	
	.addBox{
		width: 100%;
		background-color: #fff;
		position: absolute;
		bottom: 20px;
		left: 0;
		.addcyy{
			width: 80%;
			margin: 0 auto;
			padding: 10px 20px;
			border-radius: 8px;
			margin-bottom: 10px;
			text-align: center;
			background-color: #9b9b9b;
			color: #fff;
		}
	}
}
</style>
